updating oE get_bytes
get_bytes
include io.e namespace io public function get_bytes(integer fn, integer n)
reads the next bytes from a file.
Parameters:
- fn : an integer, the handle to an open file to read from.
- n : a positive integer, the number of bytes to read.
Returns:
A sequence, of length at most n, made of the bytes that could be read from the file.
Comments:
When n > 0 and the function returns a sequence of length less than n you know you have reached the end of file. Eventually, an empty sequence will be returned.
This function is normally used with files opened in binary mode, "rb". This avoids the confusing situation in text mode where Windows will convert CR LF pairs to LF.
Example 1:
integer fn fn = open("temp", "rb") -- an existing file sequence whole_file whole_file = {} sequence chunk while 1 do chunk = get_bytes(fn, 100) -- read 100 bytes at a time whole_file &= chunk -- chunk might be empty, that's ok if length(chunk) < 100 then exit end if end while close(fn) ? length(whole_file) -- should match DIR size of "temp"
See Also:
Not Categorized, Please Help
|